package com.originskyseed.platform.api.controller;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.originskyseed.platform.core.util.bean.security.MD5Util;
import com.originskyseed.platform.user.model.*;
import com.originskyseed.platform.user.service.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.common.message.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.originskyseed.platform.api.i18n.ApiResponseMsg;
import com.originskyseed.platform.api.vo.request.GetAccessTokenRequestVO;
import com.originskyseed.platform.common.api.config.QueryUrlConfig;
import com.originskyseed.platform.core.aspect.annotation.RequiredParams;
import com.originskyseed.platform.core.base.BaseController;
import com.originskyseed.platform.core.base.BaseLocaleResource;
import com.originskyseed.platform.core.base.BaseResponseBody;
import com.originskyseed.platform.core.common.code.CommonResponseCode;
import com.originskyseed.platform.core.config.bean.ConfigManager;
import com.originskyseed.platform.core.rocketmq.api.RocketMQProducer;
import com.originskyseed.platform.core.tenant.util.TenantAuthUtil;
import com.originskyseed.platform.core.tenant.util.TenantCodeUtil;
import com.originskyseed.platform.core.util.bean.PrimaryKeyGeneratorUtil;
import com.originskyseed.platform.log.model.InterfaceSynchroLog;
import com.originskyseed.platform.log.service.IInterfaceSynchroLogService;

@Controller
@RequestMapping("/anchorPlayerBusinessDataInsert")
@BaseLocaleResource(localeFileName = "i18n_api")
public class AnchorPlayerBusinessDataInsertController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(AnchorPlayerBusinessDataInsertController.class);

	@DubboReference
	private IAnchorRelateViolationService anchorRelateViolationService;

	@DubboReference
	private IAnchorRelateLiveStateService anchorRelateLiveStateService;

	@DubboReference
	private IAnchorRelateLiveService anchorRelateLiveService;

	@DubboReference
	private IPlayerRelateLoginService playerRelateLoginService;

	@DubboReference
	private IPlayerRelateViewLiveStateService playerRelateViewLiveStateService;

	@DubboReference
	private IPlayerRelateViewLiveService playerRelateViewLiveService;

	@DubboReference
	private IPlayerRelateRechargeService playerRelateRechargeService;

	@DubboReference
	private IPlayerRelateConsumeService playerRelateConsumeService;

	@DubboReference
	private IInterfaceSynchroLogService iInterfaceSynchroLogService;

	@DubboReference
	private IAnchorRelateFansService anchorRelateFansService;

	@DubboReference
	private IAnchorRelateInteractService anchorRelateInteractService;

	@DubboReference
	private IAnchorRelateByoFansService anchorRelateByoFansService;

	@DubboReference
	private IPlayerRelateChannelLogService playerRelateChannelLogService;

	@DubboReference
	private IUserInfoService userInfoService;

	@DubboReference
	private IAnchorService anchorService;

	@DubboReference
	private IPlayerService playerService;

	@DubboReference
	private IPlayerRelateAnchorRechargeService playerRelateAnchorRechargeService;

	@DubboReference
	private IPlayerRelateLastLoginService playerRelateLastLoginService;

	@DubboReference
	private IUserCumulativeChargeService userCumulativeChargeService;

	@DubboReference
	private IParameterConfigureService parameterConfigureService;

	SimpleDateFormat formatTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	/**
	 * 新增主播关联违规信息
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	/*@ResponseBody
	@RequestMapping("/anchorViolationInsert.json")
	@RequiredParams(names = { "appkey", "appSecret", "anchorViolationList" })
	public BaseResponseBody anchorViolationInsert(HttpServletRequest request, HttpServletResponse response) throws Exception {
		// 验证授权键值和授权代码
		BaseResponseBody result = this.verificationKeySecret();
		if (result != null)
			return result;

		// 记录日志
		InterfaceSynchroLog interfaceSynchroLog = new InterfaceSynchroLog();
		interfaceSynchroLog.setStartTime(new Date());
		interfaceSynchroLog.setDesc("同步主播违规信息");
		interfaceSynchroLog.setName("anchorViolationInsert.json");
		interfaceSynchroLog.setType(1);
		try {
			// 接收参数
			List<AnchorRelateViolation> list = this.getParameterList("anchorViolationList", AnchorRelateViolation.class);

			// 新增的list
			List<AnchorRelateViolation> insertList = new ArrayList<>();

			if (list != null && list.size() > 0) {
				// 查询有没有重复的第三方主键 有则去重
				List<String> otherIdList = list.stream().map(AnchorRelateViolation::getOtherId).collect(Collectors.toList());
				otherIdList = this.selectRepeatOtherId("OSI_ANCHOR_RELATE_VIOLATION", otherIdList);
				for (AnchorRelateViolation anchorRelateViolation : list) {
					boolean isInsert = selectIsRepeat(anchorRelateViolation.getOtherId(), otherIdList);
					if (isInsert) {
						anchorRelateViolation.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
						anchorRelateViolation.setCreateTime(new Date());
						insertList.add(anchorRelateViolation);
					}
				}

				// 一次性插入的数量
				int size = 500;
				// 总长度
				int length = insertList.size();
				// 计算可以分成多少组
				int num = (length + size - 1) / size;
				for (int i = 0; i < num; i++) {
					// 开始位置
					int fromIndex = i * size;
					// 结束位置
					int toIndex = (i + 1) * size < length ? (i + 1) * size : length;
					List<AnchorRelateViolation> newAnchorRelateAnnexList = insertList.subList(fromIndex, toIndex);
					anchorRelateViolationService.insertBatch(newAnchorRelateAnnexList);
				}
			}
			interfaceSynchroLog.setState(1);
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_SUCCESS.getMsg()), true);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_ERROR.getMsg()), e.getMessage(), null);

			interfaceSynchroLog.setState(2);
			interfaceSynchroLog.setErrorLog(e.getMessage());
			interfaceSynchroLog.setEndTime(new Date());
			this.iInterfaceSynchroLogService.insertSelective(interfaceSynchroLog);
		}
		return result;
	}*/

	/**
	 * 新增主播直播信息
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/anchorRelateLiveInsert.json")
	@RequiredParams(names = { "appkey", "appSecret", "anchorLiveList" })
	public BaseResponseBody anchorRelateLiveInsert(HttpServletRequest request, HttpServletResponse response) throws Exception {
		// 验证授权键值和授权代码
		BaseResponseBody result = this.verificationKeySecret();
		if (result != null)
			return result;
		// 开始时间
		long startTime = System.currentTimeMillis();
		// 记录日志
		InterfaceSynchroLog interfaceSynchroLog = new InterfaceSynchroLog();
		interfaceSynchroLog.setStartTime(new Date());
		interfaceSynchroLog.setDesc("同步主播直播信息");
		interfaceSynchroLog.setName("anchorRelateLiveInsert.json");
		interfaceSynchroLog.setType(1);
		try {
			QueryUrlConfig queryUrlConfig = ConfigManager.getInstance().parseObject(QueryUrlConfig.class);
			// 使用消息队列
			if(queryUrlConfig.getIsUseQueue()!=null && queryUrlConfig.getIsUseQueue()==1){
				// 获取租户标识
				String tenantCode = TenantCodeUtil.getInstance().getServerTenantCode();
				// 获取参数数据
				String anchorLiveListStr = this.getParameterString("anchorLiveList","");
				// 封装参数
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("tenantCode",tenantCode);
				jsonObject.put("list",anchorLiveListStr);
				Message message = new Message("synchroData","push","anchorLiveInsert",jsonObject.toJSONString().getBytes());
				SendResult sendResult = RocketMQProducer.getInstance().syncSend(message);
				//结束时间
				long endTime0 = System.currentTimeMillis();
				//System.out.println("/anchorRelateLiveInsert.json接口调用耗时(sendResult)："+sendResult+"===="+(endTime0-startTime)+"=date=="+formatTime.format(new Date()));
				if(sendResult.getSendStatus()!= SendStatus.SEND_OK){
					interfaceSynchroLog.setState(3);
					interfaceSynchroLog.setErrorLog(anchorLiveListStr);
					interfaceSynchroLog.setEndTime(new Date());
					this.iInterfaceSynchroLogService.insertSelective(interfaceSynchroLog);
					return new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_ERROR.getMsg()) , null);
				}
			}else {
				// 接受参数
				List<AnchorRelateLiveState> list = this.getParameterList("anchorLiveList", AnchorRelateLiveState.class);
				// 新增的集合
				List<AnchorRelateLiveState> insertList = new ArrayList<>();
				List<AnchorRelateLive> insertLiveList = new ArrayList<>();
				List<AnchorRelateLive> updateList = new ArrayList<>();
				if (list != null && list.size() > 0) {
					// 根据状态和直播id查询有没有重复的 有则去重
					List<AnchorRelateLiveState> queryList = this.anchorRelateLiveStateService.selectLiveIds(list);
					for (AnchorRelateLiveState anchorRelateLiveState : list) {
						// System.out.println("==anchorRelateLiveInsert=="+anchorRelateLiveState.getAnchorNickName()+"===="+anchorRelateLiveState.getAnchorId());
						boolean isInsert = true;
						for (AnchorRelateLiveState query : queryList) {
							if (anchorRelateLiveState.getLiveId().equals(query.getLiveId()) && anchorRelateLiveState.getState() == query.getState()) {
								isInsert = false;
								break;
							}
						}
						if (StringUtils.isNotBlank(anchorRelateLiveState.getAnchorId()) && isInsert) {
							anchorRelateLiveState.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
							anchorRelateLiveState.setCreateTime(new Date());
							insertList.add(anchorRelateLiveState);

							// 判断中间表是否要添加记录
							AnchorRelateLive queryAnchorRelateLive = this.anchorRelateLiveService.selectByLiveId(anchorRelateLiveState.getLiveId());
							if (queryAnchorRelateLive != null ) {
								if (queryAnchorRelateLive.getEndTime() == null && (anchorRelateLiveState.getState() == 2 || anchorRelateLiveState.getState() == 4)) {
									queryAnchorRelateLive.setEndTime(anchorRelateLiveState.getTime());
									queryAnchorRelateLive.setUpdateTime(new Date());
									if(queryAnchorRelateLive.getStartTime()!=null && queryAnchorRelateLive.getEndTime()!=null){
										queryAnchorRelateLive.setLiveTime(new BigDecimal((queryAnchorRelateLive.getEndTime().getTime()-queryAnchorRelateLive.getStartTime().getTime())/1000));
									}
									updateList.add(queryAnchorRelateLive);
								}
							} else {
								AnchorRelateLive anchorRelateLive = new AnchorRelateLive();
								anchorRelateLive.setLiveId(anchorRelateLiveState.getLiveId());
								if (anchorRelateLiveState.getState() == 1 || anchorRelateLiveState.getState() == 3) {
									anchorRelateLive.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
									anchorRelateLive.setAnchorId(anchorRelateLiveState.getAnchorId());
									anchorRelateLive.setAnchorNickName(anchorRelateLiveState.getAnchorNickName());
									anchorRelateLive.setFamilyId(anchorRelateLiveState.getFamilyId());
									anchorRelateLive.setRoomId(anchorRelateLiveState.getRoomId());
									anchorRelateLive.setStartTime(anchorRelateLiveState.getTime());
									anchorRelateLive.setCreateTime(new Date());
									anchorRelateLive.setType(anchorRelateLiveState.getType());
									for (AnchorRelateLiveState anchorRelateLiveState1 : list) {
										if (anchorRelateLiveState.getLiveId().equals(anchorRelateLiveState1.getLiveId()) && (anchorRelateLiveState1.getState() == 2 || anchorRelateLiveState1.getState() == 4)) {
											anchorRelateLive.setEndTime(anchorRelateLiveState1.getTime());
											if(anchorRelateLive.getStartTime()!=null && anchorRelateLive.getEndTime()!=null){
												anchorRelateLive.setLiveTime(new BigDecimal((anchorRelateLive.getEndTime().getTime()-anchorRelateLive.getStartTime().getTime())/1000));
											}
											break;
										}
									}
									insertLiveList.add(anchorRelateLive);
								}
							}
						}
					}

					// 一次性插入的数量
					int size = 500;
					// 总长度
					int length = insertList.size();
					// 计算可以分成多少组
					int num = (length + size - 1) / size;
					for (int i = 0; i < num; i++) {
						// 开始位置
						int fromIndex = i * size;
						// 结束位置
						int toIndex = (i + 1) * size < length ? (i + 1) * size : length;
						List<AnchorRelateLiveState> newAnchorRelateLiveStateList = insertList.subList(fromIndex, toIndex);
						this.anchorRelateLiveStateService.insertBatch(newAnchorRelateLiveStateList);
					}
					if (insertLiveList.size() > 0 || updateList.size() > 0) {
						this.anchorRelateLiveService.insertBatch(insertLiveList, updateList);
						this.anchorRelateLiveService.insertMonthBatch(insertLiveList, updateList);
					}
				}
			}
			//结束时间
			long endTime = System.currentTimeMillis();
			//System.out.println("/anchorRelateLiveInsert.json接口调用耗时："+(endTime-startTime)+"=date=="+formatTime.format(new Date()));
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_SUCCESS.getMsg()), true);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_ERROR.getMsg()), e.getMessage(), null);

			interfaceSynchroLog.setState(2);
			interfaceSynchroLog.setErrorLog(e.getMessage());
			interfaceSynchroLog.setEndTime(new Date());
			this.iInterfaceSynchroLogService.insertSelective(interfaceSynchroLog);
		}

		return result;
	}

	/**
	 * 新增玩家消费信息
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/playerRelateConsumeInsert.json")
	@RequiredParams(names = { "appkey", "appSecret", "playerRelateConsumeList" })
	public BaseResponseBody playerRelateConsumeInsert(HttpServletRequest request, HttpServletResponse response) throws Exception {
		// 验证授权键值和授权代码
		BaseResponseBody result = this.verificationKeySecret();
		if (result != null)
			return result;
		// 开始时间
		long startTime = System.currentTimeMillis();
		// 记录日志
		InterfaceSynchroLog interfaceSynchroLog = new InterfaceSynchroLog();
		interfaceSynchroLog.setStartTime(new Date());
		interfaceSynchroLog.setDesc("同步玩家消费信息");
		interfaceSynchroLog.setName("playerRelateConsumeInsert.json");
		interfaceSynchroLog.setType(1);
		try {
			QueryUrlConfig queryUrlConfig = ConfigManager.getInstance().parseObject(QueryUrlConfig.class);
			// 使用消息队列
			if(queryUrlConfig.getIsUseQueue()!=null && queryUrlConfig.getIsUseQueue()==1){
				// 获取租户标识
				String tenantCode = TenantCodeUtil.getInstance().getServerTenantCode();
				// 获取参数数据
				String playerRelateConsumeListStr = this.getParameterString("playerRelateConsumeList","");
				// 封装参数
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("tenantCode",tenantCode);
				jsonObject.put("list",playerRelateConsumeListStr);
				Message message = new Message("synchroData","push","playerRelateConsumeInsert",jsonObject.toJSONString().getBytes());
				SendResult sendResult = RocketMQProducer.getInstance().syncSend(message);
				long endTime0 = System.currentTimeMillis();
				//System.out.println("/playerRelateConsumeInsert.json接口调用耗时(sendResult)："+sendResult+"===="+(endTime0-startTime)+"=date=="+formatTime.format(new Date()));
				if (sendResult.getSendStatus() != SendStatus.SEND_OK) {
					interfaceSynchroLog.setState(3);
					interfaceSynchroLog.setErrorLog(playerRelateConsumeListStr);
					interfaceSynchroLog.setEndTime(new Date());
					this.iInterfaceSynchroLogService.insertSelective(interfaceSynchroLog);
					return new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_ERROR.getMsg()), null);
				}
			}else {
				// 请求参数
				List<PlayerRelateConsume> list = this.getParameterList("playerRelateConsumeList", PlayerRelateConsume.class);
				// 新增的集合
				List<PlayerRelateConsume> insertList = new ArrayList<>();
				if (list != null && list.size() > 0) {
					// 查询有没有重复的订单号 有则去重
					List<String> orderIds = list.stream().map(PlayerRelateConsume::getOrderId).collect(Collectors.toList());
					orderIds = this.playerRelateConsumeService.selectOrderIds(orderIds);
					for (PlayerRelateConsume playerRelateConsume : list) {
						boolean isInsert = true;
						for (String orderId : orderIds) {
							if (playerRelateConsume.getOrderId().equals(orderId)) {
								isInsert = false;
								break;
							}
						}
						if (StringUtils.isNotBlank(playerRelateConsume.getPlayerId()) && isInsert) {
							playerRelateConsume.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
							playerRelateConsume.setCreateTime(new Date());

							// 主播信息,统计主播累充金额
							Anchor anchor = this.anchorService.selectByAnchorId(playerRelateConsume.getAnchorId());
							if(anchor!=null){
								playerRelateConsume.setRechargeIsUpdate(1);
								if(anchor.getAmount()!=null){
									anchor.setTotalAmount(anchor.getAmount().add(playerRelateConsume.getAmount()));
								}else {
									anchor.setTotalAmount(playerRelateConsume.getAmount());
								}
								this.anchorService.updateByPrimaryKeySelective(anchor);
							}

							// 玩家为主播累充信息表
							PlayerRelateAnchorRecharge playerRelateAnchorRecharge = this.playerRelateAnchorRechargeService.selectByPlayerIdAndAnchorId(playerRelateConsume.getPlayerId(),playerRelateConsume.getAnchorId());
							if(playerRelateAnchorRecharge!=null){
								playerRelateAnchorRecharge.setAmount(playerRelateAnchorRecharge.getAmount().add(playerRelateConsume.getAmount()));
								playerRelateAnchorRecharge.setUpdateTime(new Date());
								this.playerRelateAnchorRechargeService.updateByPrimaryKeySelective(playerRelateAnchorRecharge);
							}else {
								playerRelateAnchorRecharge = new PlayerRelateAnchorRecharge();
								playerRelateAnchorRecharge.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
								playerRelateAnchorRecharge.setAmount(playerRelateConsume.getAmount());
								playerRelateAnchorRecharge.setAnchorId(playerRelateConsume.getAnchorId());
								playerRelateAnchorRecharge.setAnchorNickname(playerRelateConsume.getAnchorNickname());
								playerRelateAnchorRecharge.setChannelSubId(playerRelateConsume.getChannelSubId());
								playerRelateAnchorRecharge.setPlayerId(playerRelateConsume.getPlayerId());
								playerRelateAnchorRecharge.setPlayerNickname(playerRelateConsume.getPlayerNickname());
								this.playerRelateAnchorRechargeService.insertSelective(playerRelateAnchorRecharge);
							}
							insertList.add(playerRelateConsume);
						}
					}
					// 一次性插入的数量
					int size = 500;
					// 总长度
					int length = insertList.size();
					// 计算可以分成多少组
					int num = (length + size - 1) / size;
					for (int i = 0; i < num; i++) {
						// 开始位置
						int fromIndex = i * size;
						// 结束位置
						int toIndex = (i + 1) * size < length ? (i + 1) * size : length;
						List<PlayerRelateConsume> newPlayerRelateConsumeList = insertList.subList(fromIndex, toIndex);
						playerRelateConsumeService.insertBatch(newPlayerRelateConsumeList);
						playerRelateConsumeService.insertMonthBatch(newPlayerRelateConsumeList);
					}
				}
			}

			//结束时间
			long endTime = System.currentTimeMillis();
			//System.out.println("/playerRelateConsumeInsert.json接口调用耗时："+(endTime-startTime)+"=date=="+formatTime.format(new Date()));
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_SUCCESS.getMsg()), true);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_ERROR.getMsg()), e.getMessage(), null);

			interfaceSynchroLog.setState(2);
			interfaceSynchroLog.setErrorLog(e.getMessage());
			interfaceSynchroLog.setEndTime(new Date());
			this.iInterfaceSynchroLogService.insertSelective(interfaceSynchroLog);
		}
		return result;
	}

	/**
	 * 新增玩家登录信息
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/playerRelateLoginInsert.json")
	@RequiredParams(names = { "appkey", "appSecret", "playerRelateLoginList" })
	public BaseResponseBody playerRelateLoginInsert(HttpServletRequest request, HttpServletResponse response) throws Exception {
		// 验证授权键值和授权代码
		BaseResponseBody result = this.verificationKeySecret();
		if (result != null)
			return result;
		// 开始时间
		long startTime = System.currentTimeMillis();
		// 记录日志
		InterfaceSynchroLog interfaceSynchroLog = new InterfaceSynchroLog();
		interfaceSynchroLog.setStartTime(new Date());
		interfaceSynchroLog.setDesc("同步玩家登录信息");
		interfaceSynchroLog.setName("playerRelateLoginInsert.json");
		interfaceSynchroLog.setType(1);
		try {
			QueryUrlConfig queryUrlConfig = ConfigManager.getInstance().parseObject(QueryUrlConfig.class);
			// 使用消息队列
			if(queryUrlConfig.getIsUseQueue()!=null && queryUrlConfig.getIsUseQueue()==1){
				// 获取租户标识
				String tenantCode = TenantCodeUtil.getInstance().getServerTenantCode();
				// 获取参数数据
				String playerRelateLoginListStr = this.getParameterString("playerRelateLoginList","");
				// 封装参数
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("tenantCode",tenantCode);
				jsonObject.put("list",playerRelateLoginListStr);
				Message message = new Message("synchroData","push","playerRelateLoginInsert",jsonObject.toJSONString().getBytes());
				SendResult sendResult = RocketMQProducer.getInstance().syncSend(message);
				long endTime0 = System.currentTimeMillis();
				//("/playerRelateLoginInsert.json接口调用耗时(sendResult)："+sendResult+"===="+(endTime0-startTime)+"=date=="+formatTime.format(new Date()));
				if(sendResult.getSendStatus()!=SendStatus.SEND_OK){
					interfaceSynchroLog.setState(3);
					interfaceSynchroLog.setErrorLog(playerRelateLoginListStr);
					interfaceSynchroLog.setEndTime(new Date());
					this.iInterfaceSynchroLogService.insertSelective(interfaceSynchroLog);
					return new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_ERROR.getMsg()) , null);
				}
			}else {
				// 请求参数
				List<PlayerRelateLogin> list = this.getParameterList("playerRelateLoginList", PlayerRelateLogin.class);
				// 新增集合
				List<PlayerRelateLogin> insertList = new ArrayList<>();
				if (list != null && list.size() > 0) {
					// 查询有没有重复记录
					List<PlayerRelateLogin> queryList = this.playerRelateLoginService.selectPlayerIds(list);
					for (PlayerRelateLogin playerRelateLogin : list) {
						boolean isInsert = true;
						for (PlayerRelateLogin query : queryList) {
							if (playerRelateLogin.getPlayerId().equals(query.getPlayerId()) && playerRelateLogin.getLoginTime().getTime() == query.getLoginTime().getTime()) {
								isInsert = false;
								break;
							}
						}
						if (StringUtils.isNotBlank(playerRelateLogin.getPlayerId()) && isInsert) {
							// 玩家信息，更新最后登录时间
							Player player = this.playerService.selectByPlayerId(playerRelateLogin.getPlayerId());
							if(player!=null){
								player.setLastLoginTime(playerRelateLogin.getLoginTime());
								this.playerService.updateByPrimaryKeySelective(player);
							}
							// 玩家最后登录信息
							PlayerRelateLastLogin playerRelateLastLogin = this.playerRelateLastLoginService.selectByPlayerId(playerRelateLogin.getPlayerId());
							if(playerRelateLastLogin!=null){
								playerRelateLastLogin.setLoginCount(playerRelateLastLogin.getLoginCount()+1);
								playerRelateLastLogin.setLoginTime(playerRelateLogin.getLoginTime());
								playerRelateLastLogin.setLoginOutTime(playerRelateLogin.getLoginOutTime());
								playerRelateLastLogin.setRegisterTime(playerRelateLogin.getRegisterTime());
								playerRelateLastLogin.setUpdateTime(new Date());
								this.playerRelateLastLoginService.updateByPrimaryKeySelective(playerRelateLastLogin);
							}else {
								PlayerRelateLastLogin insertPlayerRelateLastLogin = new PlayerRelateLastLogin();
								insertPlayerRelateLastLogin.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
								insertPlayerRelateLastLogin.setRegisterTime(playerRelateLogin.getRegisterTime());
								insertPlayerRelateLastLogin.setLoginOutTime(playerRelateLogin.getLoginOutTime());
								insertPlayerRelateLastLogin.setLoginTime(playerRelateLogin.getLoginTime());
								insertPlayerRelateLastLogin.setLoginCount(1);
								insertPlayerRelateLastLogin.setChannelId(playerRelateLogin.getChannelId());
								insertPlayerRelateLastLogin.setChannelSubId(playerRelateLogin.getChannelSubId());
								insertPlayerRelateLastLogin.setEquipment(playerRelateLogin.getEquipment());
								insertPlayerRelateLastLogin.setEquipmentCode(playerRelateLogin.getEquipmentCode());
								insertPlayerRelateLastLogin.setImei(playerRelateLogin.getImei());
								insertPlayerRelateLastLogin.setIp(playerRelateLogin.getIp());
								insertPlayerRelateLastLogin.setNickName(playerRelateLogin.getNickName());
								insertPlayerRelateLastLogin.setPlayerId(playerRelateLogin.getPlayerId());
								this.playerRelateLastLoginService.insertSelective(insertPlayerRelateLastLogin);
							}

							// 玩家为主播累充信息表
							List<PlayerRelateAnchorRecharge> playerRelateAnchorRechargeList = this.playerRelateAnchorRechargeService.selectByPlayerId("",playerRelateLogin.getPlayerId());
							if(playerRelateAnchorRechargeList!=null&&playerRelateAnchorRechargeList.size()>0){
								List<String> playerIdList=new ArrayList<>();
								for(int i=0;i<playerRelateAnchorRechargeList.size();i++) {
									playerIdList.add(playerRelateAnchorRechargeList.get(i).getPlayerId());
								}
								this.playerRelateAnchorRechargeService.batchUpdateByPlayerId("",playerIdList,playerRelateLogin.getLoginTime(),new Date());
							}
							playerRelateLogin.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
							playerRelateLogin.setCreateTime(new Date());
							insertList.add(playerRelateLogin);
						}
					}

					// 一次性插入的数量
					int size = 500;
					// 总长度
					int length = insertList.size();
					// 计算可以分成多少组
					int num = (length + size - 1) / size;
					for (int i = 0; i < num; i++) {
						// 开始位置
						int fromIndex = i * size;
						// 结束位置
						int toIndex = (i + 1) * size < length ? (i + 1) * size : length;
						List<PlayerRelateLogin> newPlayerRelateLoginList = insertList.subList(fromIndex, toIndex);
						playerRelateLoginService.insertBatch(newPlayerRelateLoginList);
					}
				}
			}

			//结束时间
			long endTime = System.currentTimeMillis();
			//System.out.println("/playerRelateLoginInsert.json接口调用耗时："+(endTime-startTime)+"=date=="+formatTime.format(new Date()));
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_SUCCESS.getMsg()), true);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_ERROR.getMsg()), e.getMessage(), null);

			interfaceSynchroLog.setState(2);
			interfaceSynchroLog.setErrorLog(e.getMessage());
			interfaceSynchroLog.setEndTime(new Date());
			this.iInterfaceSynchroLogService.insertSelective(interfaceSynchroLog);
		}
		return result;
	}

	/**
	 * 新增玩家充值信息
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/playerRelateRechargeInsert.json")
	@RequiredParams(names = { "appkey", "appSecret", "playerRelateRechargeList" })
	public BaseResponseBody playerRelateRechargeInsert(HttpServletRequest request, HttpServletResponse response) throws Exception {
		// 验证授权键值和授权代码
		BaseResponseBody result = this.verificationKeySecret();
		if (result != null)
			return result;

		// 开始时间
		long startTime = System.currentTimeMillis();
		// 记录日志
		InterfaceSynchroLog interfaceSynchroLog = new InterfaceSynchroLog();
		interfaceSynchroLog.setStartTime(new Date());
		interfaceSynchroLog.setDesc("同步玩家充值信息");
		interfaceSynchroLog.setName("playerRelateRechargeInsert.json");
		interfaceSynchroLog.setType(1);
		try {
			QueryUrlConfig queryUrlConfig = ConfigManager.getInstance().parseObject(QueryUrlConfig.class);
			// 使用消息队列
			if(queryUrlConfig.getIsUseQueue()!=null && queryUrlConfig.getIsUseQueue()==1){
				// 获取租户标识
				String tenantCode = TenantCodeUtil.getInstance().getServerTenantCode();
				// 获取参数数据
				String playerRelateRechargeListStr = this.getParameterString("playerRelateRechargeList","");
				// 封装参数
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("tenantCode",tenantCode);
				jsonObject.put("list",playerRelateRechargeListStr);
				Message message = new Message("synchroData","push","playerRelateRechargeInsert",jsonObject.toJSONString().getBytes());
				SendResult sendResult = RocketMQProducer.getInstance().syncSend(message);
				long endTime0 = System.currentTimeMillis();
				//System.out.println("/playerRelateRechargeInsert.json接口调用耗时(sendResult)："+sendResult+"===="+(endTime0-startTime)+"=date=="+formatTime.format(new Date())+"==="+playerRelateRechargeListStr);
				if(sendResult.getSendStatus()!=SendStatus.SEND_OK){
					interfaceSynchroLog.setState(3);
					interfaceSynchroLog.setErrorLog(playerRelateRechargeListStr);
					interfaceSynchroLog.setEndTime(new Date());
					this.iInterfaceSynchroLogService.insertSelective(interfaceSynchroLog);
					return new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_ERROR.getMsg()) , null);
				}
			}else {
				// 获取租户标识
				String tenantCode = TenantCodeUtil.getInstance().getServerTenantCode();
				// 请求参数
				List<PlayerRelateRecharge> list = this.getParameterList("playerRelateRechargeList", PlayerRelateRecharge.class);
				// 新增集合
				List<PlayerRelateRecharge> insertList = new ArrayList<>();
				if (list != null && list.size() > 0) {
					// 查询有没有重复的订单号 有则去重
					List<String> orderIds = list.stream().map(PlayerRelateRecharge::getOrderId).collect(Collectors.toList());
					orderIds = this.playerRelateRechargeService.selectOrderIds(orderIds);
					// 记录累充金额
					Map<String,BigDecimal> map = new HashMap<>();
					for (PlayerRelateRecharge playerRelateRecharge : list) {
						boolean isInsert = true;
						for (String orderId : orderIds) {
							if (playerRelateRecharge.getOrderId().equals(orderId)) {
								isInsert = false;
								break;
							}
						}
						if (StringUtils.isNotBlank(playerRelateRecharge.getPlayerId()) && isInsert) {
							// 计算累充金额
							BigDecimal amount = map.get(playerRelateRecharge.getPlayerId());
							if(amount == null){
								amount = this.playerRelateRechargeService.selectAmountByPlayerId(playerRelateRecharge.getPlayerId());
							}
							if(amount!=null){
								amount = amount.add(playerRelateRecharge.getAmount());
								playerRelateRecharge.setTotalAmount(amount);
								map.put(playerRelateRecharge.getPlayerId(),amount);
							}else {
								playerRelateRecharge.setTotalAmount(playerRelateRecharge.getAmount());
								map.put(playerRelateRecharge.getPlayerId(),playerRelateRecharge.getAmount());
							}

							// 玩家信息,统计玩家累充金额
							Player player = this.playerService.selectByPlayerId(playerRelateRecharge.getPlayerId());
							if(player!=null){
								playerRelateRecharge.setRechargeIsUpdate(1);
								if(player.getAmount()!=null){
									player.setAmount(player.getAmount().add(playerRelateRecharge.getAmount()));
								}else {
									player.setAmount(playerRelateRecharge.getAmount());
								}
								this.playerService.updateByPrimaryKeySelective(player);
							}

							// 自带粉信息，统计自带粉累充金额
							AnchorRelateByoFans anchorRelateByoFans = this.anchorRelateByoFansService.selectAnchorRelateByoFansByPlayerId(playerRelateRecharge.getPlayerId());
							if(anchorRelateByoFans!=null){
								playerRelateRecharge.setBoysRechargeIsUpdate(1);
								if(anchorRelateByoFans.getAmount()!=null){
									anchorRelateByoFans.setAmount(anchorRelateByoFans.getAmount().add(playerRelateRecharge.getAmount()));
								}else {
									anchorRelateByoFans.setAmount(playerRelateRecharge.getAmount());
								}
								this.anchorRelateByoFansService.updateByPrimaryKeySelective(anchorRelateByoFans);
							}

							// 累充明细信息，统计业务员累充明细信息
							ParameterConfigure queryParam = this.parameterConfigureService.selectByCode(tenantCode,"CUMULATIVE_RECHARGE_TYPE");
							if (queryParam != null) {
								List<ParameterConfigure> parameterConfigureList = this.parameterConfigureService.selectListByParentId(queryParam.getId());
								if (parameterConfigureList.size() > 0) {
									// 子渠道总充金额
									BigDecimal total = this.playerService.selectAmountByChannelSubId(tenantCode,playerRelateRecharge.getChannelSubId());
									if(total!=null){
										for (ParameterConfigure parameterConfigure:parameterConfigureList) {
											UserCumulativeCharge queryUserCum = this.userCumulativeChargeService.selectByChannelSubIdAndType(tenantCode,playerRelateRecharge.getChannelSubId(),parameterConfigure.getName());
											if(queryUserCum==null && total.compareTo(new BigDecimal(parameterConfigure.getValue())) > 0){
												UserCumulativeCharge userCumulativeChargeAdd = new UserCumulativeCharge();
												userCumulativeChargeAdd.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
												userCumulativeChargeAdd.setType(parameterConfigure.getName());
												userCumulativeChargeAdd.setCompletionTime(playerRelateRecharge.getRechargeTime());
												userCumulativeChargeAdd.setChannelSubId(playerRelateRecharge.getChannelSubId());
												userCumulativeChargeAdd.setAmount(new BigDecimal(parameterConfigure.getValue()));
												userCumulativeChargeAdd.setCreateTime(new Date());
												this.userCumulativeChargeService.insertSelective(userCumulativeChargeAdd);
											}
										}
									}
								}
							}
							playerRelateRecharge.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
							playerRelateRecharge.setCreateTime(new Date());
							insertList.add(playerRelateRecharge);
						}
					}
					// 一次性插入的数量
					int size = 500;
					// 总长度
					int length = insertList.size();
					// 计算可以分成多少组
					int num = (length + size - 1) / size;
					for (int i = 0; i < num; i++) {
						// 开始位置
						int fromIndex = i * size;
						// 结束位置
						int toIndex = (i + 1) * size < length ? (i + 1) * size : length;
						List<PlayerRelateRecharge> newPlayerRelateRechargeList = insertList.subList(fromIndex, toIndex);
						playerRelateRechargeService.insertBatch(newPlayerRelateRechargeList);
						playerRelateRechargeService.insertMonthBatch(newPlayerRelateRechargeList);
					}
				}
			}

			//结束时间
			long endTime = System.currentTimeMillis();
			//System.out.println("/playerRelateRechargeInsert.json接口调用耗时："+(endTime-startTime)+"=date=="+formatTime.format(new Date()));
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_SUCCESS.getMsg()), true);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_ERROR.getMsg()), e.getMessage(), null);

			interfaceSynchroLog.setState(2);
			interfaceSynchroLog.setErrorLog(e.getMessage());
			interfaceSynchroLog.setEndTime(new Date());
			this.iInterfaceSynchroLogService.insertSelective(interfaceSynchroLog);
		}
		return result;
	}

	/**
	 * 新增玩家观看直播信息
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/playerRelateViewLiveInsert.json")
	@RequiredParams(names = { "appkey", "appSecret", "playerRelateViewLiveList" })
	public BaseResponseBody playerRelateViewLiveInsert(HttpServletRequest request, HttpServletResponse response) throws Exception {
		// 验证授权键值和授权代码
		BaseResponseBody result = this.verificationKeySecret();
		if (result != null)
			return result;

		// 开始时间
		long startTime = System.currentTimeMillis();
		// 记录日志
		InterfaceSynchroLog interfaceSynchroLog = new InterfaceSynchroLog();
		interfaceSynchroLog.setStartTime(new Date());
		interfaceSynchroLog.setDesc("同步玩家观看直播信息");
		interfaceSynchroLog.setName("playerRelateViewLiveInsert.json");
		interfaceSynchroLog.setType(1);
		try {
			QueryUrlConfig queryUrlConfig = ConfigManager.getInstance().parseObject(QueryUrlConfig.class);
			// 使用消息队列
			if(queryUrlConfig.getIsUseQueue()!=null && queryUrlConfig.getIsUseQueue()==1){
				// 获取租户标识
				String tenantCode = TenantCodeUtil.getInstance().getServerTenantCode();
				// 获取参数数据
				String playerRelateViewLiveListStr = this.getParameterString("playerRelateViewLiveList","");
				// 封装参数
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("tenantCode",tenantCode);
				jsonObject.put("list",playerRelateViewLiveListStr);
				Message message = new Message("synchroData","push","playerRelateViewLiveInsert",jsonObject.toJSONString().getBytes());
				SendResult sendResult = RocketMQProducer.getInstance().syncSend(message);
				long endTime0 = System.currentTimeMillis();
				//System.out.println("/playerRelateViewLiveInsert.json接口调用耗时(sendResult)："+sendResult+"===="+(endTime0-startTime)+"=date=="+formatTime.format(new Date()));
				if(sendResult.getSendStatus()!=SendStatus.SEND_OK){
					interfaceSynchroLog.setState(3);
					interfaceSynchroLog.setErrorLog(playerRelateViewLiveListStr);
					interfaceSynchroLog.setEndTime(new Date());
					this.iInterfaceSynchroLogService.insertSelective(interfaceSynchroLog);
					return new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_ERROR.getMsg()) , null);
				}
			}else {
				// 请求参数
				List<PlayerRelateViewLiveState> list = this.getParameterList("playerRelateViewLiveList", PlayerRelateViewLiveState.class);
				// 新增集合
				List<PlayerRelateViewLiveState> insertList = new ArrayList<>();
				List<PlayerRelateViewLive> liveInsertList = new ArrayList<>();
				List<PlayerRelateViewLive> updateList = new ArrayList<>();
				if (list != null && list.size() > 0) {
					// 查询有没有重复的 有则去重
					List<PlayerRelateViewLiveState> queryList = this.playerRelateViewLiveStateService.selectLiveIds(list);
					for (PlayerRelateViewLiveState playerRelateViewLiveState : list) {
						boolean isInsert = true;
						for (PlayerRelateViewLiveState query : queryList) {
							if (playerRelateViewLiveState.getLiveId().equals(query.getLiveId()) && playerRelateViewLiveState.getState() == query.getState()) {
								isInsert = false;
								break;
							}
						}
						if (StringUtils.isNotBlank(playerRelateViewLiveState.getPlayerId()) && isInsert) {
							playerRelateViewLiveState.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
							playerRelateViewLiveState.setCreateTime(new Date());
							insertList.add(playerRelateViewLiveState);

							// 判断中间表是否要添加记录
							PlayerRelateViewLive queryPlayerRelateViewLive = this.playerRelateViewLiveService.selectByLiveId(playerRelateViewLiveState.getLiveId());
							if (queryPlayerRelateViewLive != null) {
								if (queryPlayerRelateViewLive.getEndTime() == null && (playerRelateViewLiveState.getState() == 2 || playerRelateViewLiveState.getState() == 4)) {
									queryPlayerRelateViewLive.setEndTime(playerRelateViewLiveState.getTime());
									queryPlayerRelateViewLive.setUpdateTime(new Date());
									// 计算观看直播时长
									if(queryPlayerRelateViewLive.getStartTime()!=null && queryPlayerRelateViewLive.getEndTime()!=null){
										BigDecimal liveTime = new BigDecimal((queryPlayerRelateViewLive.getEndTime().getTime()-queryPlayerRelateViewLive.getStartTime().getTime())/1000);
										queryPlayerRelateViewLive.setLiveTime(liveTime);
										Player player = this.playerService.selectByPlayerId(queryPlayerRelateViewLive.getPlayerId());
										if(player!=null){
											if(player.getLiveTime()!=null){
												player.setLiveTime(player.getLiveTime().add(liveTime));
											}else {
												player.setLiveTime(liveTime);
											}
											this.playerService.updateByPrimaryKeySelective(player);
										}
									}
									updateList.add(queryPlayerRelateViewLive);
								}
							} else {
								PlayerRelateViewLive playerRelateViewLive = new PlayerRelateViewLive();
								playerRelateViewLive.setLiveId(playerRelateViewLiveState.getLiveId());
								if (playerRelateViewLiveState.getState() == 1 || playerRelateViewLiveState.getState() == 3) {
									playerRelateViewLive.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
									playerRelateViewLive.setAnchorId(playerRelateViewLiveState.getAnchorId());
									playerRelateViewLive.setPlayerId(playerRelateViewLiveState.getPlayerId());
									playerRelateViewLive.setChannelId(playerRelateViewLiveState.getChannelId());
									playerRelateViewLive.setChannelSubId(playerRelateViewLiveState.getChannelSubId());
									playerRelateViewLive.setRoomId(playerRelateViewLiveState.getRoomId());
									playerRelateViewLive.setStartTime(playerRelateViewLiveState.getTime());
									playerRelateViewLive.setCreateTime(new Date());
									for (PlayerRelateViewLiveState playerRelateViewLiveState1 : list) {
										if (playerRelateViewLiveState.getLiveId().equals(playerRelateViewLiveState1.getLiveId()) && (playerRelateViewLiveState1.getState() == 2 || playerRelateViewLiveState1.getState() == 4)) {
											playerRelateViewLive.setEndTime(playerRelateViewLiveState1.getTime());
											// 计算观看直播时长
											if(playerRelateViewLive.getStartTime()!=null && playerRelateViewLive.getEndTime()!=null){
												BigDecimal liveTime = new BigDecimal((playerRelateViewLive.getEndTime().getTime()-playerRelateViewLive.getStartTime().getTime())/1000);
												playerRelateViewLive.setLiveTime(liveTime);
												Player player = this.playerService.selectByPlayerId(playerRelateViewLive.getPlayerId());
												if(player!=null){
													if(player.getLiveTime()!=null){
														player.setLiveTime(player.getLiveTime().add(liveTime));
													}else {
														player.setLiveTime(liveTime);
													}
													this.playerService.updateByPrimaryKeySelective(player);
												}
											}
											break;
										}
									}
									liveInsertList.add(playerRelateViewLive);
								}
							}
						}
					}
					// 一次性插入的数量
					int size = 500;
					// 总长度
					int length = insertList.size();
					// 计算可以分成多少组
					int num = (length + size - 1) / size;
					for (int i = 0; i < num; i++) {
						// 开始位置
						int fromIndex = i * size;
						// 结束位置
						int toIndex = (i + 1) * size < length ? (i + 1) * size : length;
						List<PlayerRelateViewLiveState> newPlayerRelateViewLivestateList = insertList.subList(fromIndex, toIndex);
						playerRelateViewLiveStateService.insertBatch(newPlayerRelateViewLivestateList);
					}

					if (liveInsertList.size() > 0 || updateList.size() > 0) {
						this.playerRelateViewLiveService.insertBatch(liveInsertList, updateList);
						this.playerRelateViewLiveService.insertMonthBatch(liveInsertList, updateList);
					}
				}
			}

			//结束时间
			long endTime = System.currentTimeMillis();
			//System.out.println("/playerRelateViewLiveInsert.json接口调用耗时："+(endTime-startTime)+"=date=="+formatTime.format(new Date()));
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_SUCCESS.getMsg()), true);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_ERROR.getMsg()), e.getMessage(), null);

			interfaceSynchroLog.setState(2);
			interfaceSynchroLog.setErrorLog(e.getMessage());
			interfaceSynchroLog.setEndTime(new Date());
			this.iInterfaceSynchroLogService.insertSelective(interfaceSynchroLog);
		}
		return result;
	}

	/**
	 * 新增主播粉丝信息
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	/*@ResponseBody
	@RequestMapping("/anchorRelateFansInsert.json")
	@RequiredParams(names = { "appkey", "appSecret", "anchorRelateFansList" })
	public BaseResponseBody anchorRelateFansInsert(HttpServletRequest request, HttpServletResponse response) throws Exception {
		// 验证授权键值和授权代码
		BaseResponseBody result = this.verificationKeySecret();
		if (result != null)
			return result;

		// 记录日志
		InterfaceSynchroLog interfaceSynchroLog = new InterfaceSynchroLog();
		interfaceSynchroLog.setStartTime(new Date());
		interfaceSynchroLog.setDesc("同步主播粉丝信息");
		interfaceSynchroLog.setName("anchorRelateFansInsert.json");
		interfaceSynchroLog.setType(1);
		try {
			// 请求参数
			List<AnchorRelateFans> list = this.getParameterList("anchorRelateFansList", AnchorRelateFans.class);

			// 新增集合
			List<AnchorRelateFans> insertList = new ArrayList<>();
			if (list != null && list.size() > 0) {
				// 查询有没有重复的第三方主键 有则去重
				List<String> otherIdList = list.stream().map(AnchorRelateFans::getOtherId).collect(Collectors.toList());
				otherIdList = this.selectRepeatOtherId("OSI_ANCHOR_RELATE_FANS", otherIdList);

				for (AnchorRelateFans anchorRelateFans : list) {
					boolean isInsert = selectIsRepeat(anchorRelateFans.getOtherId(), otherIdList);
					if (isInsert) {
						anchorRelateFans.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
						anchorRelateFans.setCreateTime(new Date());
						insertList.add(anchorRelateFans);
					}
				}

				// 一次性插入的数量
				int size = 500;
				// 总长度
				int length = insertList.size();
				// 计算可以分成多少组
				int num = (length + size - 1) / size;
				for (int i = 0; i < num; i++) {
					// 开始位置
					int fromIndex = i * size;
					// 结束位置
					int toIndex = (i + 1) * size < length ? (i + 1) * size : length;
					List<AnchorRelateFans> newAnchorRelateFansList = insertList.subList(fromIndex, toIndex);
					anchorRelateFansService.insertBatch(newAnchorRelateFansList);
				}
			}
			interfaceSynchroLog.setState(1);
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_SUCCESS.getMsg()), true);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_ERROR.getMsg()), e.getMessage(), null);

			interfaceSynchroLog.setState(2);
			interfaceSynchroLog.setErrorLog(e.getMessage());
			interfaceSynchroLog.setEndTime(new Date());
			this.iInterfaceSynchroLogService.insertSelective(interfaceSynchroLog);
		}
		return result;
	}*/

	/**
	 * 新增打招呼信息
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/anchorRelateInteract.json")
	@RequiredParams(names = { "appkey", "appSecret", "anchorRelateInteractList" })
	public BaseResponseBody anchorRelateInteract(HttpServletRequest request, HttpServletResponse response) throws Exception {
		// 验证授权键值和授权代码
		BaseResponseBody result = this.verificationKeySecret();
		if (result != null)
			return result;

		// 开始时间
		long startTime = System.currentTimeMillis();
		// 记录日志
		InterfaceSynchroLog interfaceSynchroLog = new InterfaceSynchroLog();
		interfaceSynchroLog.setStartTime(new Date());
		interfaceSynchroLog.setDesc("同步打招呼信息");
		interfaceSynchroLog.setName("anchorRelateInteractList.json");
		interfaceSynchroLog.setType(1);
		try {
			QueryUrlConfig queryUrlConfig = ConfigManager.getInstance().parseObject(QueryUrlConfig.class);
			// 使用消息队列
			if(queryUrlConfig.getIsUseQueue()!=null && queryUrlConfig.getIsUseQueue()==1){
				// 获取租户标识
				String tenantCode = TenantCodeUtil.getInstance().getServerTenantCode();
				// 获取参数数据
				String anchorRelateInteractListStr = this.getParameterString("anchorRelateInteractList","");
				// 封装参数
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("tenantCode",tenantCode);
				jsonObject.put("list",anchorRelateInteractListStr);
				Message message = new Message("synchroData","push","anchorRelateInteractInsert",jsonObject.toJSONString().getBytes());
				SendResult sendResult = RocketMQProducer.getInstance().syncSend(message);
				long endTime0 = System.currentTimeMillis();
				//System.out.println("/anchorRelateInteract.json接口调用耗时(sendResult)："+sendResult+"===="+(endTime0-startTime)+"=date=="+formatTime.format(new Date()));
				if(sendResult.getSendStatus()!=SendStatus.SEND_OK){
					interfaceSynchroLog.setState(3);
					interfaceSynchroLog.setErrorLog(anchorRelateInteractListStr);
					interfaceSynchroLog.setEndTime(new Date());
					this.iInterfaceSynchroLogService.insertSelective(interfaceSynchroLog);
					return new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_ERROR.getMsg()) , null);
				}
			}else {
				// 请求参数
				List<AnchorRelateInteract> list = this.getParameterList("anchorRelateInteractList", AnchorRelateInteract.class);
				// 新增集合
				List<AnchorRelateInteract> insertList = new ArrayList<>();
				if (list != null && list.size() > 0) {
					// 查询有没有重复的记录 有则去重
					List<AnchorRelateInteract> queryList = this.anchorRelateInteractService.selectFormIds(list);
					for (AnchorRelateInteract anchorRelateInteract : list) {
						boolean isInsert = true;
						for (AnchorRelateInteract query : queryList) {
							if (anchorRelateInteract.getFromId().equals(query.getFromId()) && anchorRelateInteract.getTime().getTime() == query.getTime().getTime()) {
								isInsert = false;
								break;
							}
						}
						if (isInsert) {
							anchorRelateInteract.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
							anchorRelateInteract.setCreateTime(new Date());
							insertList.add(anchorRelateInteract);
						}
					}

					// 一次性插入的数量
					int size = 500;
					// 总长度
					int length = insertList.size();
					// 计算可以分成多少组
					int num = (length + size - 1) / size;
					for (int i = 0; i < num; i++) {
						// 开始位置
						int fromIndex = i * size;
						// 结束位置
						int toIndex = (i + 1) * size < length ? (i + 1) * size : length;
						List<AnchorRelateInteract> newAnchorRelateInteractList = insertList.subList(fromIndex, toIndex);
						anchorRelateInteractService.insertBatch(newAnchorRelateInteractList);
					}
				}
			}

			//结束时间
			long endTime = System.currentTimeMillis();
			//System.out.println("/anchorRelateInteract.json接口调用耗时："+(endTime-startTime)+"=date=="+formatTime.format(new Date()));
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_SUCCESS.getMsg()), true);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_ERROR.getMsg()), e.getMessage(), null);

			interfaceSynchroLog.setState(2);
			interfaceSynchroLog.setErrorLog(e.getMessage());
			interfaceSynchroLog.setEndTime(new Date());
			this.iInterfaceSynchroLogService.insertSelective(interfaceSynchroLog);
		}
		return result;
	}

	/**
	 * 新增自带粉信息
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/anchorRelateByoFans.json")
	@RequiredParams(names = { "appkey", "appSecret", "anchorRelateByoFansList" })
	public BaseResponseBody anchorRelateByoFans(HttpServletRequest request, HttpServletResponse response) throws Exception {
		// 验证授权键值和授权代码
		BaseResponseBody result = this.verificationKeySecret();
		if (result != null)
			return result;

		// 开始时间
		long startTime = System.currentTimeMillis();
		// 记录日志
		InterfaceSynchroLog interfaceSynchroLog = new InterfaceSynchroLog();
		interfaceSynchroLog.setStartTime(new Date());
		interfaceSynchroLog.setDesc("同步自带粉信息");
		interfaceSynchroLog.setName("anchorRelateByoFans.json");
		interfaceSynchroLog.setType(1);
		try {
			QueryUrlConfig queryUrlConfig = ConfigManager.getInstance().parseObject(QueryUrlConfig.class);
			// 使用消息队列
			if(queryUrlConfig.getIsUseQueue()!=null && queryUrlConfig.getIsUseQueue()==1){
				// 获取租户标识
				String tenantCode = TenantCodeUtil.getInstance().getServerTenantCode();
				// 获取参数数据
				String anchorRelateByoFansListStr = this.getParameterString("anchorRelateByoFansList","");
				// 封装参数
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("tenantCode",tenantCode);
				jsonObject.put("list",anchorRelateByoFansListStr);
				Message message = new Message("synchroData","push","anchorRelateByoFansInsert",jsonObject.toJSONString().getBytes());
				SendResult sendResult = RocketMQProducer.getInstance().syncSend(message);
				long endTime0 = System.currentTimeMillis();
				//System.out.println("/anchorRelateByoFans.json接口调用耗时(sendResult)："+sendResult+"===="+(endTime0-startTime)+"=date=="+formatTime.format(new Date()));
				if(sendResult.getSendStatus()!=SendStatus.SEND_OK){
					interfaceSynchroLog.setState(3);
					interfaceSynchroLog.setErrorLog(anchorRelateByoFansListStr);
					interfaceSynchroLog.setEndTime(new Date());
					this.iInterfaceSynchroLogService.insertSelective(interfaceSynchroLog);
					return new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_ERROR.getMsg()) , null);
				}

			}else {
				// 请求参数
				List<AnchorRelateByoFans> list = this.getParameterList("anchorRelateByoFansList", AnchorRelateByoFans.class);
				// 新增集合
				List<AnchorRelateByoFans> insertList = new ArrayList<>();
				if (list != null && list.size() > 0) {
					// 查询有没有重复的记录 有则去重
					List<AnchorRelateByoFans> queryList = this.anchorRelateByoFansService.selectByoFansId(list);
					for (AnchorRelateByoFans anchorRelateByoFans : list) {
						boolean isInsert = true;
						for (AnchorRelateByoFans query : queryList) {
							if (anchorRelateByoFans.getAnchorId().equals(query.getAnchorId()) && anchorRelateByoFans.getByoFansId() == query.getByoFansId()) {
								isInsert = false;
								break;
							}
						}
						if (isInsert) {
							anchorRelateByoFans.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
							anchorRelateByoFans.setCreateTime(new Date());
							insertList.add(anchorRelateByoFans);
						}
					}

					// 一次性插入的数量
					int size = 500;
					// 总长度
					int length = insertList.size();
					// 计算可以分成多少组
					int num = (length + size - 1) / size;
					for (int i = 0; i < num; i++) {
						// 开始位置
						int fromIndex = i * size;
						// 结束位置
						int toIndex = (i + 1) * size < length ? (i + 1) * size : length;
						List<AnchorRelateByoFans> newAnchorRelateByoFansList = insertList.subList(fromIndex, toIndex);
						anchorRelateByoFansService.insertBatch(newAnchorRelateByoFansList);
					}
				}
			}

			//结束时间
			long endTime = System.currentTimeMillis();
			//System.out.println("/anchorRelateByoFans.json接口调用耗时："+(endTime-startTime)+"=date=="+formatTime.format(new Date()));
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_SUCCESS.getMsg()), true);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_ERROR.getMsg()), e.getMessage(), null);

			interfaceSynchroLog.setState(2);
			interfaceSynchroLog.setErrorLog(e.getMessage());
			interfaceSynchroLog.setEndTime(new Date());
			this.iInterfaceSynchroLogService.insertSelective(interfaceSynchroLog);
		}
		return result;
	}

	/**
	 * 新增玩家渠道改绑记录
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/playerRelateChannelLogInsert.json")
	@RequiredParams(names = { "appkey", "appSecret", "playerRelateChannelLogList" })
	public BaseResponseBody playerRelateChannelLogInsert(HttpServletRequest request, HttpServletResponse response) throws Exception {
		// 验证授权键值和授权代码
		BaseResponseBody result = this.verificationKeySecret();
		if (result != null)
			return result;

		// 开始时间
		long startTime = System.currentTimeMillis();
		// 记录日志
		InterfaceSynchroLog interfaceSynchroLog = new InterfaceSynchroLog();
		interfaceSynchroLog.setStartTime(new Date());
		interfaceSynchroLog.setDesc("同步玩家渠道改绑记录信息");
		interfaceSynchroLog.setName("playerRelateChannelLogInsert.json");
		interfaceSynchroLog.setType(1);
		try {
			QueryUrlConfig queryUrlConfig = ConfigManager.getInstance().parseObject(QueryUrlConfig.class);
			// 使用消息队列
			if(queryUrlConfig.getIsUseQueue()!=null && queryUrlConfig.getIsUseQueue()==1){
				// 获取租户标识
				String tenantCode = TenantCodeUtil.getInstance().getServerTenantCode();
				// 获取参数数据
				String playerRelateChannelLogListStr = this.getParameterString("playerRelateChannelLogList","");
				// 封装参数
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("tenantCode",tenantCode);
				jsonObject.put("list",playerRelateChannelLogListStr);
				Message message = new Message("synchroData","push","playerRelateChannelLogInsert",jsonObject.toJSONString().getBytes());
				SendResult sendResult = RocketMQProducer.getInstance().syncSend(message);
				long endTime0 = System.currentTimeMillis();
				//System.out.println("/playerRelateChannelLogInsert.json接口调用耗时(sendResult)："+sendResult+"===="+(endTime0-startTime)+"=date=="+formatTime.format(new Date()));
				if(sendResult.getSendStatus()!=SendStatus.SEND_OK){
					interfaceSynchroLog.setState(3);
					interfaceSynchroLog.setErrorLog(playerRelateChannelLogListStr);
					interfaceSynchroLog.setEndTime(new Date());
					this.iInterfaceSynchroLogService.insertSelective(interfaceSynchroLog);
					return new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_ERROR.getMsg()) , null);
				}
			}else {
				// 请求参数
				List<PlayerRelateChannelLog> list = this.getParameterList("playerRelateChannelLogList", PlayerRelateChannelLog.class);
				// 新增集合
				List<PlayerRelateChannelLog> insertList = new ArrayList<>();
				if (list != null && list.size() > 0) {
					// 查询有没有重复的记录 有则去重
					List<PlayerRelateChannelLog> queryList = this.playerRelateChannelLogService.selectChannelSubIdAndOldChannelSubId(list);
					for (PlayerRelateChannelLog playerRelateChannelLog : list) {
						boolean isInsert = true;
						for (PlayerRelateChannelLog query : queryList) {
							if (playerRelateChannelLog.getChannelSubId().equals(query.getChannelSubId()) && playerRelateChannelLog.getOldChannelSubId().equals(query.getOldChannelSubId()) && playerRelateChannelLog.getChangeChannelTime().getTime() == query.getChangeChannelTime().getTime()) {
								isInsert = false;
								break;
							}
						}
						if (isInsert) {
							playerRelateChannelLog.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
							playerRelateChannelLog.setCreateTime(new Date());
							playerRelateChannelLog.setSource(1);
							playerRelateChannelLog.setIsUpdate(0);
							insertList.add(playerRelateChannelLog);
						}
					}

					// 一次性插入的数量
					int size = 500;
					// 总长度
					int length = insertList.size();
					// 计算可以分成多少组
					int num = (length + size - 1) / size;
					for (int i = 0; i < num; i++) {
						// 开始位置
						int fromIndex = i * size;
						// 结束位置
						int toIndex = (i + 1) * size < length ? (i + 1) * size : length;
						List<PlayerRelateChannelLog> newPlayerRelateChannelLog = insertList.subList(fromIndex, toIndex);
						playerRelateChannelLogService.insertBatch(newPlayerRelateChannelLog);
					}
				}
			}

			//结束时间
			long endTime = System.currentTimeMillis();
			//System.out.println("/playerRelateChannelLogInsert.json接口调用耗时："+(endTime-startTime)+"=date=="+formatTime.format(new Date()));
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_SUCCESS.getMsg()), true);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_ERROR.getMsg()), e.getMessage(), null);

			interfaceSynchroLog.setState(2);
			interfaceSynchroLog.setErrorLog(e.getMessage());
			interfaceSynchroLog.setEndTime(new Date());
			this.iInterfaceSynchroLogService.insertSelective(interfaceSynchroLog);
		}
		return result;
	}


	/**
	 * 新增玩家渠道改绑记录
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/playerRelateChannelLogInsert1.json")
	@RequiredParams(names = { "appkey", "appSecret", "playerRelateChannelLogList" })
	public BaseResponseBody playerRelateChannelLogInsert1(HttpServletRequest request, HttpServletResponse response) throws Exception {
		// 验证授权键值和授权代码
		BaseResponseBody result = this.verificationKeySecret();
		if (result != null)
			return result;

		// 开始时间
		long startTime = System.currentTimeMillis();
		// 记录日志
		/*InterfaceSynchroLog interfaceSynchroLog = new InterfaceSynchroLog();
		interfaceSynchroLog.setStartTime(new Date());
		interfaceSynchroLog.setDesc("同步玩家渠道改绑记录信息");
		interfaceSynchroLog.setName("playerRelateChannelLogInsert.json");
		interfaceSynchroLog.setType(1);
		try {
			QueryUrlConfig queryUrlConfig = ConfigManager.getInstance().parseObject(QueryUrlConfig.class);
			// 使用消息队列
			if(queryUrlConfig.getIsUseQueue()!=null && queryUrlConfig.getIsUseQueue()==1){
				// 获取租户标识
				String tenantCode = TenantCodeUtil.getInstance().getServerTenantCode();
				// 获取参数数据
				String playerRelateChannelLogListStr = this.getParameterString("playerRelateChannelLogList","");
				// 封装参数
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("tenantCode",tenantCode);
				jsonObject.put("list",playerRelateChannelLogListStr);
				Message message = new Message("synchroData","push","playerRelateChannelLogInsert",jsonObject.toJSONString().getBytes());
				SendResult sendResult = RocketMQProducer.getInstance().syncSend(message);
				long endTime0 = System.currentTimeMillis();
				System.out.println("/playerRelateChannelLogInsert.json接口调用耗时(sendResult)："+sendResult+"===="+(endTime0-startTime)+"=date=="+formatTime.format(new Date()));
				if(sendResult.getSendStatus()!=SendStatus.SEND_OK){
					interfaceSynchroLog.setState(3);
					interfaceSynchroLog.setErrorLog(playerRelateChannelLogListStr);
					interfaceSynchroLog.setEndTime(new Date());
					this.iInterfaceSynchroLogService.insertSelective(interfaceSynchroLog);
					return new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_ERROR.getMsg()) , null);
				}
			}else {
				// 请求参数
				List<PlayerRelateChannelLog> list = this.getParameterList("playerRelateChannelLogList", PlayerRelateChannelLog.class);
				// 新增集合
				List<PlayerRelateChannelLog> insertList = new ArrayList<>();
				if (list != null && list.size() > 0) {
					// 查询有没有重复的记录 有则去重
					List<PlayerRelateChannelLog> queryList = this.playerRelateChannelLogService.selectChannelSubIdAndOldChannelSubId(list);
					for (PlayerRelateChannelLog playerRelateChannelLog : list) {
						boolean isInsert = true;
						for (PlayerRelateChannelLog query : queryList) {
							if (playerRelateChannelLog.getChannelSubId().equals(query.getChannelSubId()) && playerRelateChannelLog.getOldChannelSubId().equals(query.getOldChannelSubId()) && playerRelateChannelLog.getChangeChannelTime().getTime() == query.getChangeChannelTime().getTime()) {
								isInsert = false;
								break;
							}
						}
						if (isInsert) {
							playerRelateChannelLog.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
							playerRelateChannelLog.setCreateTime(new Date());
							playerRelateChannelLog.setSource(1);
							playerRelateChannelLog.setIsUpdate(0);
							insertList.add(playerRelateChannelLog);
						}
					}

					// 一次性插入的数量
					int size = 500;
					// 总长度
					int length = insertList.size();
					// 计算可以分成多少组
					int num = (length + size - 1) / size;
					for (int i = 0; i < num; i++) {
						// 开始位置
						int fromIndex = i * size;
						// 结束位置
						int toIndex = (i + 1) * size < length ? (i + 1) * size : length;
						List<PlayerRelateChannelLog> newPlayerRelateChannelLog = insertList.subList(fromIndex, toIndex);
						playerRelateChannelLogService.insertBatch(newPlayerRelateChannelLog);
					}
				}
			}

			//结束时间
			long endTime = System.currentTimeMillis();
			System.out.println("/playerRelateChannelLogInsert.json接口调用耗时："+(endTime-startTime)+"=date=="+formatTime.format(new Date()));
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_SUCCESS.getMsg()), true);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.SAVE_ERROR.getMsg()), e.getMessage(), null);

			interfaceSynchroLog.setState(2);
			interfaceSynchroLog.setErrorLog(e.getMessage());
			interfaceSynchroLog.setEndTime(new Date());
			this.iInterfaceSynchroLogService.insertSelective(interfaceSynchroLog);
		}*/
		//结束时间
		long endTime = System.currentTimeMillis();
		System.out.println("/playerRelateChannelLogInsert.json接口调用耗时："+(endTime-startTime)+"=date=="+formatTime.format(new Date()));
		return result;
	}

	/**
	 * 查询有没有重复的第三方主键
	 * 
	 * @param tableName
	 * @param otherIdList
	 * @return
	 * @throws Exception
	 */
	private List<String> selectRepeatOtherId(String tableName, List<String> otherIdList) throws Exception {
		Map<String, Object> map = new HashMap<>();
		map.put("tableName", tableName);
		map.put("list", otherIdList);
		return this.userInfoService.selectRepeatOtherId(map);
	}

	/**
	 * 判断是否不重复
	 * 
	 * @param otherId
	 * @param otherIdList
	 * @return
	 * @throws Exception
	 */
	private boolean selectIsRepeat(String otherId, List<String> otherIdList) throws Exception {
		boolean isInsert = true;
		for (String id : otherIdList) {
			if (otherId.equals(id)) {
				isInsert = false;
				break;
			}
		}
		return isInsert;
	}

	/**
	 * 验证授权键值和授权代码
	 * 
	 * @return
	 */
	private BaseResponseBody verificationKeySecret() {
		// 请求对象
		GetAccessTokenRequestVO requestVO = this.getParameterBean(GetAccessTokenRequestVO.class);
		// 获取第三方授权返回码
		int responseCode = TenantAuthUtil.getInstance().getAuthenticatedResponseCode(requestVO.getAppkey(), requestVO.getAppSecret());
		if (responseCode == 2004) {
			return null;
		} else {
			return new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), ApiResponseMsg.APP_KEY_APP_SECRET_ERROR.getMsg()), false);
		}
	}


	public static void main(String[] args) throws Exception{
		//test1(args);
		//test2(args);
		//test3(args);
		test4(args);
		//test5(args);
		//test6(args);
		//DefaultMQProducer defaultMQProducer=new DefaultMQProducer("PushProducer");
		//defaultMQProducer.setNamesrvAddr("119.29.90.153:9876");
		//defaultMQProducer.start();
		//Message message=new Message("testA","xxx","content".getBytes());
		//SendResult sendResult=defaultMQProducer.send(message);

		//System.out.println("xxxx");
	}


	public static void test1(String[] args) throws Exception{
		Map<String,String> map = new HashMap<>();
		map.put("appkey","73b7e46531c1422aa42b19117985e185");
		map.put("appSecret","+I0btye3dy0=");
		// 玩家信息集合
		JSONArray jsonArray = new JSONArray();
		JSONObject playerJson = new JSONObject();
		playerJson.put("account","cs2021913a");
		playerJson.put("playerId","cs2021913a");
		playerJson.put("tradeUnionId","cs2021913a");
		playerJson.put("nickName","cs2021913a");
		playerJson.put("belongBusinessId","cs2021913a");
		playerJson.put("channelId","cs2021913a");
		playerJson.put("channelSubId","cs2021913a");
		playerJson.put("equipment","cs2021913a");
		playerJson.put("equipmentCode","cs2021913a");
		playerJson.put("imei","imei");
		playerJson.put("registTime",new Date());
		jsonArray.add(playerJson);
		JSONObject playerJson1 = new JSONObject();
		playerJson1.put("account","cs2021913b");
		playerJson1.put("playerId","cs2021913b");
		playerJson1.put("tradeUnionId","cs2021913b");
		playerJson1.put("nickName","cs2021913b");
		playerJson1.put("belongBusinessId","cs2021913b");
		playerJson1.put("channelId","cs2021913b");
		playerJson1.put("channelSubId","cs2021913b");
		playerJson1.put("equipment","cs2021913b");
		playerJson1.put("equipmentCode","cs2021913b");
		playerJson1.put("imei","imei");
		playerJson1.put("registTime",new Date());
		jsonArray.add(playerJson1);


		String api_timestamp=System.currentTimeMillis()+"";
		String api_nonce=genReqID();

		map.put("api_timestamp",api_timestamp);
		map.put("api_nonce",api_nonce);
		map.put("playerList",jsonArray.toJSONString());
		map.put("system_type","core-admin");

		JSONObject json =JSONObject.parseObject(JSONObject.toJSONString(map));
		String md5Str=getServerSign(json);
		map.put("api_sign",md5Str);

		CloseableHttpClient httpclient = null;
		CloseableHttpResponse response = null;

		try {
			//String url = "http://119.29.90.153:8040/platform-api/familyAnchorInsert/playerInsert.json";
			String url = "http://dy.originskyseed.com:8000/platform-api/familyAnchorInsert/playerInsert.json";
			//请求发起客户端
			httpclient = HttpClients.createDefault();
			//参数集合
			List postParams = new ArrayList();
			//遍历参数并添加到集合
			for(Map.Entry<String, String> entry:map.entrySet()){
				postParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
			}
			//通过post方式访问
			HttpPost post = new HttpPost(url);
			HttpEntity paramEntity = new UrlEncodedFormEntity(postParams,"UTF-8");
			post.setEntity(paramEntity);
			response = httpclient.execute(post);
			HttpEntity valueEntity = response.getEntity();
			String content = EntityUtils.toString(valueEntity);
			System.out.println(content);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(httpclient != null){
				try {
					httpclient.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if(response != null){
				try {
					response.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

	public static void test2(String[] args) throws Exception{
		Map<String,String> map = new HashMap<>();
		map.put("appkey","73b7e46531c1422aa42b19117985e185");
		map.put("appSecret","+I0btye3dy0=");
		// 玩家消费信息集合
		JSONArray jsonArray = new JSONArray();
		JSONObject playerJson = new JSONObject();
		playerJson.put("playerId","cs2021913a");
		playerJson.put("anchorId","cs2021913a");
		playerJson.put("channelId","cs2021913a");
		playerJson.put("channelSubId","cs2021913a");
		playerJson.put("orderId","11111111111");
		playerJson.put("orderContent","消费内容");
		playerJson.put("amount","1");
		playerJson.put("consumeTime",new Date());
		playerJson.put("roomId","ceshi");
		playerJson.put("type","1");
		jsonArray.add(playerJson);
		JSONObject playerJson1 = new JSONObject();
		playerJson1.put("playerId","cs2021913a");
		playerJson1.put("anchorId","cs2021913a");
		playerJson1.put("channelId","cs2021913a");
		playerJson1.put("channelSubId","cs2021913a");
		playerJson1.put("orderId","222222222222");
		playerJson1.put("orderContent","消费内容");
		playerJson1.put("amount","3");
		playerJson1.put("consumeTime",new Date());
		playerJson1.put("roomId","ceshi");
		playerJson1.put("type","1");
		jsonArray.add(playerJson1);


		String api_timestamp=System.currentTimeMillis()+"";
		String api_nonce=genReqID();

		map.put("api_timestamp",api_timestamp);
		map.put("api_nonce",api_nonce);
		map.put("playerRelateConsumeList",jsonArray.toJSONString());
		map.put("system_type","core-admin");

		JSONObject json =JSONObject.parseObject(JSONObject.toJSONString(map));
		String md5Str=getServerSign(json);
		map.put("api_sign",md5Str);

		CloseableHttpClient httpclient = null;
		CloseableHttpResponse response = null;

		try {
			//String url = "http://119.29.90.153:8040/platform-api/familyAnchorInsert/playerInsert.json";
			String url = "http://dy.originskyseed.com:8000/platform-api/anchorPlayerBusinessDataInsert/playerRelateConsumeInsert.json";
			//请求发起客户端
			httpclient = HttpClients.createDefault();
			//参数集合
			List postParams = new ArrayList();
			//遍历参数并添加到集合
			for(Map.Entry<String, String> entry:map.entrySet()){
				postParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
			}
			//通过post方式访问
			HttpPost post = new HttpPost(url);
			HttpEntity paramEntity = new UrlEncodedFormEntity(postParams,"UTF-8");
			post.setEntity(paramEntity);
			response = httpclient.execute(post);
			HttpEntity valueEntity = response.getEntity();
			String content = EntityUtils.toString(valueEntity);
			System.out.println(content);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(httpclient != null){
				try {
					httpclient.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if(response != null){
				try {
					response.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

	public static void test3(String[] args) throws Exception{
		Map<String,String> map = new HashMap<>();
		map.put("appkey","73b7e46531c1422aa42b19117985e185");
		map.put("appSecret","+I0btye3dy0=");
		// 玩家登录信息集合
		JSONArray jsonArray = new JSONArray();
		JSONObject playerJson = new JSONObject();
		playerJson.put("playerId","cs2021913a");
		playerJson.put("nickName","cs2021913a");
		playerJson.put("loginTime",new Date());
		playerJson.put("channelId","cs2021913a");
		playerJson.put("channelSubId","cs2021913a");
		playerJson.put("equipmentCode","1");
		playerJson.put("ip","127.0.0.1");
		playerJson.put("imei","imei");
		jsonArray.add(playerJson);



		String api_timestamp=System.currentTimeMillis()+"";
		String api_nonce=genReqID();

		map.put("api_timestamp",api_timestamp);
		map.put("api_nonce",api_nonce);
		map.put("playerRelateLoginList",jsonArray.toJSONString());
		map.put("system_type","core-admin");

		JSONObject json =JSONObject.parseObject(JSONObject.toJSONString(map));
		String md5Str=getServerSign(json);
		map.put("api_sign",md5Str);

		CloseableHttpClient httpclient = null;
		CloseableHttpResponse response = null;

		try {
			//String url = "http://119.29.90.153:8040/platform-api/familyAnchorInsert/playerInsert.json";
			String url = "http://dy.originskyseed.com:8000/platform-api/anchorPlayerBusinessDataInsert/playerRelateLoginInsert.json";
			//请求发起客户端
			httpclient = HttpClients.createDefault();
			//参数集合
			List postParams = new ArrayList();
			//遍历参数并添加到集合
			for(Map.Entry<String, String> entry:map.entrySet()){
				postParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
			}
			//通过post方式访问
			HttpPost post = new HttpPost(url);
			HttpEntity paramEntity = new UrlEncodedFormEntity(postParams,"UTF-8");
			post.setEntity(paramEntity);
			response = httpclient.execute(post);
			HttpEntity valueEntity = response.getEntity();
			String content = EntityUtils.toString(valueEntity);
			System.out.println(content);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(httpclient != null){
				try {
					httpclient.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if(response != null){
				try {
					response.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

	public static void test4(String[] args) throws Exception{
		Map<String,String> map = new HashMap<>();
		map.put("appkey","73b7e46531c1422aa42b19117985e185");
		map.put("appSecret","+I0btye3dy0=");
		// 玩家充值信息集合
		JSONArray jsonArray = new JSONArray();
		JSONObject playerJson1 = new JSONObject();
		playerJson1.put("playerId","cs2021913a");
		playerJson1.put("channelId","cs2021913a");
		playerJson1.put("channelSubId","cs2021913a");
		playerJson1.put("orderId","111111111111");
		playerJson1.put("software","1");
		playerJson1.put("amount","1000");
		playerJson1.put("rechargeTime",new Date());
		playerJson1.put("goods","获得物品");
		playerJson1.put("payType","1");
		jsonArray.add(playerJson1);
		JSONObject playerJson = new JSONObject();
		playerJson.put("playerId","cs2021913a");
		playerJson.put("channelId","cs2021913a");
		playerJson.put("channelSubId","cs2021913a");
		playerJson.put("orderId","222222222222");
		playerJson.put("software","1");
		playerJson.put("amount","1000");
		playerJson.put("rechargeTime",new Date());
		playerJson.put("goods","获得物品");
		playerJson.put("payType","1");
		jsonArray.add(playerJson);



		String api_timestamp=System.currentTimeMillis()+"";
		String api_nonce=genReqID();

		map.put("api_timestamp",api_timestamp);
		map.put("api_nonce",api_nonce);
		map.put("playerRelateRechargeList",jsonArray.toJSONString());
		map.put("system_type","core-admin");

		JSONObject json =JSONObject.parseObject(JSONObject.toJSONString(map));
		String md5Str=getServerSign(json);
		map.put("api_sign",md5Str);

		CloseableHttpClient httpclient = null;
		CloseableHttpResponse response = null;

		try {
			//String url = "http://119.29.90.153:8040/platform-api/familyAnchorInsert/playerInsert.json";
			String url = "http://dy.originskyseed.com:8000/platform-api/anchorPlayerBusinessDataInsert/playerRelateRechargeInsert.json";
			//请求发起客户端
			httpclient = HttpClients.createDefault();
			//参数集合
			List postParams = new ArrayList();
			//遍历参数并添加到集合
			for(Map.Entry<String, String> entry:map.entrySet()){
				postParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
			}
			//通过post方式访问
			HttpPost post = new HttpPost(url);
			HttpEntity paramEntity = new UrlEncodedFormEntity(postParams,"UTF-8");
			post.setEntity(paramEntity);
			response = httpclient.execute(post);
			HttpEntity valueEntity = response.getEntity();
			String content = EntityUtils.toString(valueEntity);
			System.out.println(content);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(httpclient != null){
				try {
					httpclient.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if(response != null){
				try {
					response.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

	public static void test5(String[] args) throws Exception{
		Map<String,String> map = new HashMap<>();
		map.put("appkey","73b7e46531c1422aa42b19117985e185");
		map.put("appSecret","+I0btye3dy0=");
		// 玩家观看直播集合
		JSONArray jsonArray = new JSONArray();
		JSONObject playerJson1 = new JSONObject();
		playerJson1.put("playerId","cs2021913a");
		playerJson1.put("anchorId","cs2021913a");
		playerJson1.put("channelId","cs2021913a");
		playerJson1.put("channelSubId","cs2021913a");
		playerJson1.put("roomId","1");
		playerJson1.put("time",new Date());
		playerJson1.put("state","1");
		playerJson1.put("liveId","ceshi");
		jsonArray.add(playerJson1);
		Thread.sleep(5000);
		JSONObject playerJson = new JSONObject();
		playerJson.put("playerId","cs2021913a");
		playerJson.put("anchorId","cs2021913a");
		playerJson.put("channelId","cs2021913a");
		playerJson.put("channelSubId","cs2021913a");
		playerJson.put("roomId","1");
		playerJson.put("time",new Date());
		playerJson.put("state","2");
		playerJson.put("liveId","ceshi");
		jsonArray.add(playerJson);



		String api_timestamp=System.currentTimeMillis()+"";
		String api_nonce=genReqID();

		map.put("api_timestamp",api_timestamp);
		map.put("api_nonce",api_nonce);
		map.put("playerRelateViewLiveList",jsonArray.toJSONString());
		map.put("system_type","core-admin");

		JSONObject json =JSONObject.parseObject(JSONObject.toJSONString(map));
		String md5Str=getServerSign(json);
		map.put("api_sign",md5Str);

		CloseableHttpClient httpclient = null;
		CloseableHttpResponse response = null;

		try {
			//String url = "http://119.29.90.153:8040/platform-api/familyAnchorInsert/playerInsert.json";
			String url = "http://dy.originskyseed.com:8000/platform-api/anchorPlayerBusinessDataInsert/playerRelateViewLiveInsert.json";
			//请求发起客户端
			httpclient = HttpClients.createDefault();
			//参数集合
			List postParams = new ArrayList();
			//遍历参数并添加到集合
			for(Map.Entry<String, String> entry:map.entrySet()){
				postParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
			}
			//通过post方式访问
			HttpPost post = new HttpPost(url);
			HttpEntity paramEntity = new UrlEncodedFormEntity(postParams,"UTF-8");
			post.setEntity(paramEntity);
			response = httpclient.execute(post);
			HttpEntity valueEntity = response.getEntity();
			String content = EntityUtils.toString(valueEntity);
			System.out.println(content);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(httpclient != null){
				try {
					httpclient.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if(response != null){
				try {
					response.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

	public static void test6(String[] args) throws Exception{
		Map<String,String> map = new HashMap<>();
		map.put("appkey","73b7e46531c1422aa42b19117985e185");
		map.put("appSecret","+I0btye3dy0=");
		// 主播直播信息集合
		JSONArray jsonArray = new JSONArray();
		JSONObject playerJson1 = new JSONObject();
		playerJson1.put("familyId","cs2021913a");
		playerJson1.put("anchorId","cs2021913a");
		playerJson1.put("anchorNickName","cs2021913a");
		playerJson1.put("roomId","ceshi1");
		playerJson1.put("time",new Date());
		playerJson1.put("state","1");
		playerJson1.put("type","2");
		playerJson1.put("liveId","ceshi");
		jsonArray.add(playerJson1);
		Thread.sleep(5000);
		JSONObject playerJson = new JSONObject();
		playerJson.put("familyId","cs2021913a");
		playerJson.put("anchorId","cs2021913a");
		playerJson.put("anchorNickName","cs2021913a");
		playerJson.put("roomId","ceshi1");
		playerJson.put("time",new Date());
		playerJson.put("state","2");
		playerJson.put("type","2");
		playerJson.put("liveId","ceshi");
		jsonArray.add(playerJson);



		String api_timestamp=System.currentTimeMillis()+"";
		String api_nonce=genReqID();

		map.put("api_timestamp",api_timestamp);
		map.put("api_nonce",api_nonce);
		map.put("anchorLiveList",jsonArray.toJSONString());
		map.put("system_type","core-admin");

		JSONObject json =JSONObject.parseObject(JSONObject.toJSONString(map));
		String md5Str=getServerSign(json);
		map.put("api_sign",md5Str);

		CloseableHttpClient httpclient = null;
		CloseableHttpResponse response = null;

		try {
			//String url = "http://119.29.90.153:8040/platform-api/familyAnchorInsert/playerInsert.json";
			String url = "http://dy.originskyseed.com:8000/platform-api/anchorPlayerBusinessDataInsert/anchorRelateLiveInsert.json";
			//请求发起客户端
			httpclient = HttpClients.createDefault();
			//参数集合
			List postParams = new ArrayList();
			//遍历参数并添加到集合
			for(Map.Entry<String, String> entry:map.entrySet()){
				postParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
			}
			//通过post方式访问
			HttpPost post = new HttpPost(url);
			HttpEntity paramEntity = new UrlEncodedFormEntity(postParams,"UTF-8");
			post.setEntity(paramEntity);
			response = httpclient.execute(post);
			HttpEntity valueEntity = response.getEntity();
			String content = EntityUtils.toString(valueEntity);
			System.out.println(content);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(httpclient != null){
				try {
					httpclient.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if(response != null){
				try {
					response.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}


	public static String genReqID() {
		return UUID.randomUUID().toString().replace("-", "").toUpperCase();
	}

	/**
	 * 获取服务器签名
	 *
	 * @param params
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	private static String getServerSign(JSONObject params) throws UnsupportedEncodingException {
		String result = null;

		if (null != params) {
			// 排除签名字段
			//params.remove(KEY_SIGN);

			// 递归排序编码
			String encodeStr = recursiveSortAndEncrypt(params);

			// 进行字符加密
			result = MD5Util.encrypt(encodeStr);
		}

		return result;
	}


	/**
	 * 获取服务器签名
	 *
	 * @param params
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	private static String getServerSignToJsonArray(JSONArray params) throws UnsupportedEncodingException {
		String result = null;

		if (null != params) {
			// 排除签名字段
			//params.remove(KEY_SIGN);

			// 递归排序编码
			String encodeStr = recursiveSortAndEncrypt(params);

			// 进行字符加密
			result = MD5Util.encrypt(encodeStr);
		}

		return result;
	}
	/**
	 * 递归排序加密
	 *
	 * @param object
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	private static String recursiveSortAndEncrypt(Object object) throws UnsupportedEncodingException {
		StringBuilder result = new StringBuilder();
		if (object instanceof JSONObject) {
			JSONObject jsonObject = JSONObject.parseObject(object.toString());

			// 字典排序
			List<String> keys = new ArrayList<String>();
			keys.addAll(jsonObject.keySet());
			Collections.sort(keys);

			// 遍历对象
			for (int i = 0; i < keys.size(); i++) {
				String key = keys.get(i);
				String value = recursiveSortAndEncrypt(jsonObject.get(key));

				// 排除空字符串
				if (StringUtils.isNotBlank(value)) {
					result.append(key).append(value);
				}
			}
		} else if (object instanceof JSONArray) {
			JSONArray jsonArray = JSONArray.parseArray(object.toString());

			// 遍历对象
			for (int i = 0; i < jsonArray.size(); i++) {
				result.append(recursiveSortAndEncrypt(jsonArray.get(i)));
			}
		} else {
			result.append(URLEncoder.encode(object.toString(), "UTF-8").replaceAll("\\+", "%20")); // 特殊处理空格
		}
		return result.toString();
	}

}
